package org.nterlearning.datamodel.catalog.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import org.nterlearning.datamodel.catalog.model.CourseRequirement;
import org.nterlearning.datamodel.catalog.model.CourseRequirementModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.Locale;
import java.util.Map;

/**
 * The base model implementation for the CourseRequirement service. Represents a row in the &quot;CATALOG_CourseRequirement&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link org.nterlearning.datamodel.catalog.model.CourseRequirementModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link CourseRequirementImpl}.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see CourseRequirementImpl
 * @see org.nterlearning.datamodel.catalog.model.CourseRequirement
 * @see org.nterlearning.datamodel.catalog.model.CourseRequirementModel
 * @generated
 */
public class CourseRequirementModelImpl extends BaseModelImpl<CourseRequirement>
    implements CourseRequirementModel {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. All methods that expect a course requirement model instance should use the {@link org.nterlearning.datamodel.catalog.model.CourseRequirement} interface instead.
     */
    public static final String TABLE_NAME = "CATALOG_CourseRequirement";
    public static final Object[][] TABLE_COLUMNS = {
            { "courseRequirementId", Types.BIGINT },
            { "courseId", Types.BIGINT },
            { "requirementType", Types.VARCHAR },
            { "requirementValue", Types.VARCHAR }
        };
    public static final String TABLE_SQL_CREATE = "create table CATALOG_CourseRequirement (courseRequirementId LONG not null primary key,courseId LONG,requirementType VARCHAR(50) null,requirementValue STRING null)";
    public static final String TABLE_SQL_DROP = "drop table CATALOG_CourseRequirement";
    public static final String DATA_SOURCE = "liferayDataSource";
    public static final String SESSION_FACTORY = "liferaySessionFactory";
    public static final String TX_MANAGER = "liferayTransactionManager";
    public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.entity.cache.enabled.org.nterlearning.datamodel.catalog.model.CourseRequirement"),
            true);
    public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.finder.cache.enabled.org.nterlearning.datamodel.catalog.model.CourseRequirement"),
            true);
    public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.column.bitmask.enabled.org.nterlearning.datamodel.catalog.model.CourseRequirement"),
            true);
    public static long COURSEID_COLUMN_BITMASK = 1L;
    public static long REQUIREMENTTYPE_COLUMN_BITMASK = 2L;
    public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
                "lock.expiration.time.org.nterlearning.datamodel.catalog.model.CourseRequirement"));
    private static ClassLoader _classLoader = CourseRequirement.class.getClassLoader();
    private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
            CourseRequirement.class
        };
    private long _courseRequirementId;
    private long _courseId;
    private long _originalCourseId;
    private boolean _setOriginalCourseId;
    private String _requirementType;
    private String _originalRequirementType;
    private String _requirementValue;
    private String _requirementValueCurrentLanguageId;
    private transient ExpandoBridge _expandoBridge;
    private long _columnBitmask;
    private CourseRequirement _escapedModelProxy;

    public CourseRequirementModelImpl() {
    }

    public long getPrimaryKey() {
        return _courseRequirementId;
    }

    public void setPrimaryKey(long primaryKey) {
        setCourseRequirementId(primaryKey);
    }

    public Serializable getPrimaryKeyObj() {
        return new Long(_courseRequirementId);
    }

    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    public Class<?> getModelClass() {
        return CourseRequirement.class;
    }

    public String getModelClassName() {
        return CourseRequirement.class.getName();
    }

    public long getCourseRequirementId() {
        return _courseRequirementId;
    }

    public void setCourseRequirementId(long courseRequirementId) {
        _courseRequirementId = courseRequirementId;
    }

    public long getCourseId() {
        return _courseId;
    }

    public void setCourseId(long courseId) {
        _columnBitmask |= COURSEID_COLUMN_BITMASK;

        if (!_setOriginalCourseId) {
            _setOriginalCourseId = true;

            _originalCourseId = _courseId;
        }

        _courseId = courseId;
    }

    public long getOriginalCourseId() {
        return _originalCourseId;
    }

    public String getRequirementType() {
        if (_requirementType == null) {
            return StringPool.BLANK;
        } else {
            return _requirementType;
        }
    }

    public void setRequirementType(String requirementType) {
        _columnBitmask |= REQUIREMENTTYPE_COLUMN_BITMASK;

        if (_originalRequirementType == null) {
            _originalRequirementType = _requirementType;
        }

        _requirementType = requirementType;
    }

    public String getOriginalRequirementType() {
        return GetterUtil.getString(_originalRequirementType);
    }

    public String getRequirementValue() {
        if (_requirementValue == null) {
            return StringPool.BLANK;
        } else {
            return _requirementValue;
        }
    }

    public String getRequirementValue(Locale locale) {
        String languageId = LocaleUtil.toLanguageId(locale);

        return getRequirementValue(languageId);
    }

    public String getRequirementValue(Locale locale, boolean useDefault) {
        String languageId = LocaleUtil.toLanguageId(locale);

        return getRequirementValue(languageId, useDefault);
    }

    public String getRequirementValue(String languageId) {
        return LocalizationUtil.getLocalization(getRequirementValue(),
            languageId);
    }

    public String getRequirementValue(String languageId, boolean useDefault) {
        return LocalizationUtil.getLocalization(getRequirementValue(),
            languageId, useDefault);
    }

    public String getRequirementValueCurrentLanguageId() {
        return _requirementValueCurrentLanguageId;
    }

    @JSON
    public String getRequirementValueCurrentValue() {
        Locale locale = getLocale(_requirementValueCurrentLanguageId);

        return getRequirementValue(locale);
    }

    public Map<Locale, String> getRequirementValueMap() {
        return LocalizationUtil.getLocalizationMap(getRequirementValue());
    }

    public void setRequirementValue(String requirementValue) {
        _requirementValue = requirementValue;
    }

    public void setRequirementValue(String requirementValue, Locale locale) {
        setRequirementValue(requirementValue, locale, LocaleUtil.getDefault());
    }

    public void setRequirementValue(String requirementValue, Locale locale,
        Locale defaultLocale) {
        String languageId = LocaleUtil.toLanguageId(locale);
        String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

        if (Validator.isNotNull(requirementValue)) {
            setRequirementValue(LocalizationUtil.updateLocalization(
                    getRequirementValue(), "RequirementValue",
                    requirementValue, languageId, defaultLanguageId));
        } else {
            setRequirementValue(LocalizationUtil.removeLocalization(
                    getRequirementValue(), "RequirementValue", languageId));
        }
    }

    public void setRequirementValueCurrentLanguageId(String languageId) {
        _requirementValueCurrentLanguageId = languageId;
    }

    public void setRequirementValueMap(Map<Locale, String> requirementValueMap) {
        setRequirementValueMap(requirementValueMap, LocaleUtil.getDefault());
    }

    public void setRequirementValueMap(
        Map<Locale, String> requirementValueMap, Locale defaultLocale) {
        if (requirementValueMap == null) {
            return;
        }

        Locale[] locales = LanguageUtil.getAvailableLocales();

        for (Locale locale : locales) {
            String requirementValue = requirementValueMap.get(locale);

            setRequirementValue(requirementValue, locale, defaultLocale);
        }
    }

    public long getColumnBitmask() {
        return _columnBitmask;
    }

    @Override
    public CourseRequirement toEscapedModel() {
        if (_escapedModelProxy == null) {
            _escapedModelProxy = (CourseRequirement) ProxyUtil.newProxyInstance(_classLoader,
                    _escapedModelProxyInterfaces,
                    new AutoEscapeBeanHandler(this));
        }

        return _escapedModelProxy;
    }

    @Override
    public ExpandoBridge getExpandoBridge() {
        if (_expandoBridge == null) {
            _expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
                    CourseRequirement.class.getName(), getPrimaryKey());
        }

        return _expandoBridge;
    }

    @Override
    public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
        getExpandoBridge().setAttributes(serviceContext);
    }

    @Override
    public Object clone() {
        CourseRequirementImpl courseRequirementImpl = new CourseRequirementImpl();

        courseRequirementImpl.setCourseRequirementId(getCourseRequirementId());
        courseRequirementImpl.setCourseId(getCourseId());
        courseRequirementImpl.setRequirementType(getRequirementType());
        courseRequirementImpl.setRequirementValue(getRequirementValue());

        courseRequirementImpl.resetOriginalValues();

        return courseRequirementImpl;
    }

    public int compareTo(CourseRequirement courseRequirement) {
        long primaryKey = courseRequirement.getPrimaryKey();

        if (getPrimaryKey() < primaryKey) {
            return -1;
        } else if (getPrimaryKey() > primaryKey) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        CourseRequirement courseRequirement = null;

        try {
            courseRequirement = (CourseRequirement) obj;
        } catch (ClassCastException cce) {
            return false;
        }

        long primaryKey = courseRequirement.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public void resetOriginalValues() {
        CourseRequirementModelImpl courseRequirementModelImpl = this;

        courseRequirementModelImpl._originalCourseId = courseRequirementModelImpl._courseId;

        courseRequirementModelImpl._setOriginalCourseId = false;

        courseRequirementModelImpl._originalRequirementType = courseRequirementModelImpl._requirementType;

        courseRequirementModelImpl._columnBitmask = 0;
    }

    @Override
    public CacheModel<CourseRequirement> toCacheModel() {
        CourseRequirementCacheModel courseRequirementCacheModel = new CourseRequirementCacheModel();

        courseRequirementCacheModel.courseRequirementId = getCourseRequirementId();

        courseRequirementCacheModel.courseId = getCourseId();

        courseRequirementCacheModel.requirementType = getRequirementType();

        String requirementType = courseRequirementCacheModel.requirementType;

        if ((requirementType != null) && (requirementType.length() == 0)) {
            courseRequirementCacheModel.requirementType = null;
        }

        courseRequirementCacheModel.requirementValue = getRequirementValue();

        String requirementValue = courseRequirementCacheModel.requirementValue;

        if ((requirementValue != null) && (requirementValue.length() == 0)) {
            courseRequirementCacheModel.requirementValue = null;
        }

        return courseRequirementCacheModel;
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(9);

        sb.append("{courseRequirementId=");
        sb.append(getCourseRequirementId());
        sb.append(", courseId=");
        sb.append(getCourseId());
        sb.append(", requirementType=");
        sb.append(getRequirementType());
        sb.append(", requirementValue=");
        sb.append(getRequirementValue());
        sb.append("}");

        return sb.toString();
    }

    public String toXmlString() {
        StringBundler sb = new StringBundler(16);

        sb.append("<model><model-name>");
        sb.append("org.nterlearning.datamodel.catalog.model.CourseRequirement");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>courseRequirementId</column-name><column-value><![CDATA[");
        sb.append(getCourseRequirementId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>courseId</column-name><column-value><![CDATA[");
        sb.append(getCourseId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>requirementType</column-name><column-value><![CDATA[");
        sb.append(getRequirementType());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>requirementValue</column-name><column-value><![CDATA[");
        sb.append(getRequirementValue());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
